#include<iostream>
#include<cstring>
using namespace std;
const int N = 1e3 + 10;
typedef pair<int, int> PII;
#define x first
#define y second
int arr[N][N];
PII pre[N][N];
int n;
PII q[N * N];
bool st[N][N];
int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
void bfs(int x, int y)
{
	int hh = 0, tt = 0;
	q[0] = { x,y };
	st[x][y] = 1;
	while (hh <= tt) {
		PII t = q[hh++];
		int x = t.x;
		int y = t.y;
		if (x == 0 && y == 0) {
			return;
		}
		for (int i = 0; i < 4; i++) {
			int a = x + dx[i];
			int b = y + dy[i];
			if (a < 0 || b < 0 || a >= n || b >= n || arr[a][b]) {
				continue;
			}
			if (st[a][b]) {
				continue;
			}
			//cout << a << " " << b << endl;
			st[a][b] = 1;
			pre[a][b] = { x,y };
			q[++tt] = { a,b };
		}
	}

}
int main()
{
	cin >> n;
	memset(pre, -1, sizeof(pre));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> arr[i][j];
		}
	}
	bfs(n - 1, n - 1);
	int u = 0, v = 0;
	while (u >= 0 && v >= 0) {
		cout << u << " " << v << endl;
		PII t = pre[u][v];
		u = t.x;
		v = t.y;
	}
	return 0;
}